<?php if(!defined('HOST'))die('not access');?>
<script >
    var c;
    $(document).ready(function(){
        {params};
        var comid = params.comid;
        if(comid == undefined) comid = '';
        var atype=params.atype;
        var a = $('#veiw_{rand}').bootstable({
            tablename:'zbcg_new_info',celleditor:true,sort:'id',dir:'desc',modedir:'{mode}:{dir}',params:{'atype':atype, 'comid':comid, 'utype':1},checked:true,fanye:true,
            url:js.getajaxurl('getProjectInfoList','{mode}','{dir}',{'utype':1}),fanye:true,
            columns:[{
                text:'采购单位',dataIndex:'companyname'
            },{
                text:'预算总价',dataIndex:'budget'
            },{
                text:'资金来源',dataIndex:'funds_type'
            },{
                text:'项目名称',dataIndex:'name'
            },{
                text:'明细科目',dataIndex:'detail'
            },{
                text:'项目类别',dataIndex:'type'
            },{
                text:'组织形式',dataIndex:'catalogue'
            },{
                text:'采购方式',dataIndex:'buymode'
            },{
                text:'备注',dataIndex:'gathernote'
            },{
                text:'代理机构',dataIndex:'proxygov'
            },{
                text:'项目负责人',dataIndex:'projecterName'
            },{
                text:'完成时间',dataIndex:'updt'
            }],
            rendertr:function(d){
                var s = '';
                if(d.level==2)s='style="color:red"';
                return s;
            }
        });

        c = {
            search:function(){
                var s=$('#name_{rand}').val();
                var type = $("#type_{rand}").val();
                var sdate=$('#search_sdate_{rand}').val();
                var edate=$('#search_edate_{rand}').val();
                var stbudget=$('#stbudget_{rand}').val();
                var enbudget=$('#enbudget_{rand}').val();
                var bugtype=$('#bugtype_{rand}').val();
                var comid=$('#unit_{rand}').val();
                var projectadminer=$('#projectadminer_{rand}').val();

                a.setparams({name:s,sdate:sdate,edate:edate, type:type, comid:comid, projectadminer:projectadminer,bugtype:bugtype,stbudget:stbudget,enbudget:enbudget,utype:1},true);
            },
            daochu:function(){
                a.exceldown();
            },

        };
        js.initbtn(c);
    });
</script>


<div>
    <table>
        <tr>
            <td style="width:10%;">
                <input class="form-control" id="name_{rand}" placeholder="项目名称" />
            </td>
            <td nowrap style="width:10%;padding-left:10px;">
                <select id="unit_{rand}" class="form-control" >
                    <option value="">二级单位</option>
                </select>
            </td>
            <td style="width:10%;padding-left:10px;">
                <select class="form-control" id="type_{rand}">
                    <option value="">项目类别</option>
                    <option value="货物类">货物类</option>
                    <option value="服务类">服务类</option>
                    <option value="工程类">工程类</option>
                    <option value="电子卖场">电子卖场</option>
                </select>
            </td>
            <td style="width:10%;padding-left:10px;">
                <select id="bugtype_{rand}" class="form-control" >
                    <option value="">采购方式</option>
                    <option value="单一来源">单一来源</option>
                    <option value="公开招标">公开招标</option>
                    <option value="竞争性谈判">竞争性谈判</option>
                    <option value="竞争性磋商">竞争性磋商</option>
                    <option value="询价">询价</option>
                    <option value="直采">直采</option>
                    <option value="无过程采购">无过程采购</option>
                </select>
            </td>
            <td style="width:10%;padding-left:10px;">
                <select class="form-control" id="projectadminer_{rand}">

                </select>
            </td>
            <td style="width:10%"></td>
            <td style="width:10%"></td>
            <td style="width:10%"></td>
            <td style="width:10%"></td>
        </tr>
        <tr>
            <td colspan="2">
                完成时间：
                <input onclick="js.datechange(this,'date')" value="" class="inputs datesss" inputtype="date" readonly="" name="search_sdate" id="search_sdate_{rand}" style="width:30%;max-width:110px;">
                <input onclick="js.datechange(this,'date')" value="" class="inputs datesss" inputtype="date" readonly="" name="search_edate" id="search_edate_{rand}" style="width:30%;max-width:110px;">
            </td>
            <td style="padding-left:10px;width:13%;">
                <button class="btn" id="t_year_{rand}" type="button">年</button>
                <button class="btn" id="t_season_{rand}" type="button">季</button>
                <button class="btn" id="t_month_{rand}" type="button">月</button>
            </td>
            <td colspan="2" style="padding-left:10px;">
                预算金额：
                <input value="" class="inputs" id="stbudget_{rand}" style="width:28%;max-width:110px;">
                到
                <input value="" class="inputs" id="enbudget_{rand}" style="width:28%;max-width:110px;">
            </td>
            <td nowrap style="padding-left:10px">
                <button class="btn btn-default" click="search" type="button">搜索</button>
                <button class="btn btn-default" id="downExce_{rand}" type="button">下载</button>
            </td>
        </tr>
    </table>
</div>
<div class="blank10"></div>
<div id="veiw_{rand}"></div>
<script>
    $(document).ready(function(){
        var date=new Date;
        var y = date.getFullYear()
        $('#search_sdate_{rand}').val(y+'-01-01');

        function loadProjectadminer(){
            js.ajax(js.getajaxurl('loadProjectadminner','index','cg'),
                {

                },function(s){
                    var ccc ="<option value=''>项目负责人</option>";
                    $.each(s, function(i, field){
                        ccc += "<option value='"+field.id+"'>"+field.name+"</option>";
                    });
                    $("#projectadminer_{rand}").html(ccc);
                },'get,json',false,'');

            $.ajax({ url: "./index.php?a=getCompanyList&m=main&d=report&ajaxbool=true", success: function(obj){
                    var ccc ="<option value=''>采购单位</option>";
                    obj = JSON.parse(obj);
                    data = obj.rows;
                    for(i=0;i<data.length;i++){
                        ccc += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
                    };
                    $('#unit_{rand}').html(ccc);
                }});
        }
        loadProjectadminer();
    });

    //下載文件
    $(document).ready(function(){
        $("#downExce_{rand}").click(function(){
            var s=$('#name_{rand}').val();
            var type = $("#type_{rand}").val();
            var sdate=$('#search_sdate_{rand}').val();
            var edate=$('#search_edate_{rand}').val();
            var stbudget=$('#stbudget_{rand}').val();
            var enbudget=$('#enbudget_{rand}').val();
            var bugtype=$('#bugtype_{rand}').val();
            var comid=$('#unit_{rand}').val();
            var projectadminer=$('#projectadminer_{rand}').val();
            top.location='./index.php?a=wtjhmxb&m=office|index&d=cg&ajaxbool=true&name='+name+'&type='+type+'&sdate='+sdate+'&edate='+edate+'&comid='+comid+'&bugtype='+bugtype+'&stbudget='+stbudget+'&enbudget='+enbudget+'&projectadminer'+projectadminer+'&utype=1';
        });

        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth();
        var month = month + 1;
        if(month.toString().length == 1) {
            month = '0' + month;
        }
        var day = date.getDate();
        $("#t_year_{rand}").click(function(){
            var sdate=$('#search_sdate_{rand}').val(year+'-01-01');
            var edate=$('#search_edate_{rand}').val(year+'-12-31');
        });
        $("#t_season_{rand}").click(function(){
            stime = '';
            etime = '';
            switch(true) {
                case (month <= 3):
                    stime = year+'-01-01';
                    etime = year+'-03-31';
                    break;
                case (3 < month <= 6):
                    stime = year+'-04-01';
                    etime = year+'-06-30';
                    break;
                case (6 < month <= 9):
                    stime = year+'-07-01';
                    etime = year+'-09-30';
                    break;
                case (9 < month <= 12):
                    stime = year+'-10-01';
                    etime = year+'-12-31';
                    break;
            }
            var sdate=$('#search_sdate_{rand}').val(stime);
            var edate=$('#search_edate_{rand}').val(etime);
        });
        $("#t_month_{rand}").click(function(){
            var lastDay= new Date(year,month,0).getDate();
            var sdate=$('#search_sdate_{rand}').val(year+'-'+month+'-01');
            var edate=$('#search_edate_{rand}').val(year+'-'+month+'-'+lastDay);
        });
    });
</script>